package com.mineoj.controller;

import com.mineoj.common.BaseResponse;
import com.mineoj.common.ResultUtils;
import com.mineoj.model.dto.competitionquestion.CompetitionQuestionAddRequest;
import com.mineoj.model.entity.User;
import com.mineoj.service.CompetitionQuestionService;
import com.mineoj.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 
 *
 
 */
@RestController
@RequestMapping("/competition_quetion")
@Slf4j
public class CompetitionQuestionController {

    @Resource
    private CompetitionQuestionService questionListTitleService;

    @Resource
    private UserService userService;

    /**
     * 向比赛 添加 / 删除 题目
     *
     * @param questionListTitleAddRequest
     * @param request
     * @return resultNum 本次变化数
     */
    @PostMapping("/")
    public BaseResponse<Integer> addCompetitionQuestion(@RequestBody CompetitionQuestionAddRequest questionListTitleAddRequest,
            HttpServletRequest request) {
        // 登录才能添加
        final User loginUser = userService.getLoginUser(request);
        int result = questionListTitleService.addCompetitionQuestion(questionListTitleAddRequest, loginUser);
        return ResultUtils.success(result);
    }

}
